<?php
/**
 * User:ayou chow
 * Date: 2019-12-09
 * Time: 15:52
 */

namespace app\common\model;


use think\facade\Cache;
use think\Model;

class BlackKeywordModel extends Model
{

    protected static function init()
    {
        BlackKeywordModel::afterInsert(function ($user) {
            Cache::store('redis')->set('keywordsUpdate', 1);
        });
        BlackKeywordModel::afterUpdate(function ($user) {
            Cache::store('redis')->set('keywordsUpdate', 1);
        });
        BlackKeywordModel::afterDelete(function ($user) {
            Cache::store('redis')->set('keywordsUpdate', 1);
        });
    }


    public function admin()
    {
        return $this->hasOne(AdminModel::class, 'id', 'admin_id')->field("id, name as nick_name");
    }

    public function device()
    {
        return $this->hasMany(UserModel::class, 'device', 'device')->field('id,nick_name');
    }
}